package com.atguigu.oss.controller;


import com.atguigu.commonutils.R;
import com.atguigu.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(description = "阿里云文件管理")
@CrossOrigin
@RestController
@RequestMapping("/oss/file")
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation(value="教师头像文件上传")
    @PostMapping("teacherAvatarUpload")
    public R teacherAvatarUpload(
            @ApiParam(name = "file",value="文件",required = true)
            @RequestParam("teacherAvatar")
                    MultipartFile file){
        String uploadUrl = fileService.upload(file,"teacherAvatarImg");
        return R.ok().message("上传成功").data("url",uploadUrl);
    }

    @ApiOperation(value="课程封面文件上传")
    @PostMapping("courseCoverUpload")
    public R courseCoverUpload(
            @ApiParam(name = "file",value="文件",required = true)
            @RequestParam("file")
            MultipartFile file){
        String uploadUrl = fileService.upload(file,"courseCoverImg");
        return R.ok().message("上传成功").data("url",uploadUrl);
    }


}
